package com.barry.pattern.observation;

import java.util.LinkedList;

/**
 * @author Gong
 *	Subject 作为通知者，告诉观察者 Observer
 */
public class Subject {
	LinkedList< Observer> observers;

	public Subject() {
		this.observers = new LinkedList< Observer>();
	}

	public void addObserver(Observer observer) {
		observers.add( observer);
	}

	void removeObserver(Observer observer) {
		observers.remove(observer);
	}

	public void notifyAlls() {
		//挨个通知observer,让他们执行各自的update方法
		System.err.println("老師來了，Suject發起警報！");
		for (Observer observer:observers){
			observer.update();
		}
	}

	public void notifySomeone() {

	}
}
